package me.pplay.playtalk;

import java.util.LinkedList;
import java.util.List;

import me.pplay.playtalk.protocol.TpAuth;
import me.pplay.playtalk.protocol.TpChat;
import me.pplay.playtalk.protocol.TpChatRoom;
import me.pplay.playtalk.util.PlayTalkUtil;
import android.app.Activity;
import android.app.Application;

public class ApplicationTrans extends Application {
	private TpAuth tpAuth = new TpAuth();
	private TpChat tpChat = new TpChat();
	private TpChatRoom tpChatRoom = new TpChatRoom();
	private List<Activity> activityList = new LinkedList<Activity>();

	public TpAuth getTpAuth() {
		return tpAuth;
	}

	public TpChat getTpChat() {
		return tpChat;
	}

	public TpChatRoom getTpChatRoom() {
		return tpChatRoom;
	}
	public void tp_exit()
	{
		PlayTalkUtil.isLogin = false;
		tpAuth.tp_auth_stop();
		tpChatRoom.tp_chatroom_stop();
		tpChat.tp_chat_stop();
	}
	// 添加Activity到容器中
	public void addActivityToContainer(Activity activity) {
		activityList.add(activity);
	}
	// 遍历所有Activity并finish
	public void removeActivityToContainer(Activity activity) {
		activityList.remove(activity);
	}
	// 遍历所有Activity并finish
	public void closeAllActivity() {
		for (Activity activity : activityList) {
			if(activity != null && !activity.isFinishing())
				activity.finish();
		}
		activityList.clear();
	}
	public void applicationClear()
	{
		closeAllActivity();
		tp_exit();
	}
	// 遍历所有Activity并finish
	public void exit() {
		applicationClear();
		System.exit(0);
	}
}
